<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bindKey</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const bindKey =
            (context, handler, ...bindArgs) =>
                (...args) =>
                    context[handler].apply(context, [...bindArgs, ...args]);
        const freddy = {
            user: 'fred',
            greet: function (greeting, punctuation) {
                return greeting + ' ' + this.user + punctuation;
            }
        };
        const freddyBound = bindKey(freddy, 'greet');
        console.log(freddyBound('hi', '!')); // 'hi fred!'
    </script>
</body>

</html>